//
//  RSSystemSettingTableVC.m
//  RSTools
//
//  Created by thinkjoy on 2017/9/14.
//  Copyright © 2017年 杜瑞胜. All rights reserved.
//

#import "RSSystemSettingTableVC.h"
#import "RSSystemUtit.h"

#pragma mark - 日志开关
#ifdef DEBUG
#define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#define DLog(...)
#endif

@interface RSSystemSettingTableVC ()
{
    NSMutableArray  * _resourceDataMuAry;
//    NSMutableDictionary * _resourceDataMuDic;
}

@end

@implementation RSSystemSettingTableVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _resourceDataMuAry  =   [NSMutableArray array];
    [_resourceDataMuAry addObject:@{@"1":@[
                                            @{@"设置":@(RSPrefsRoot_Setting)},
                                            @{@"wefi":@(RSPrefsRoot_WIFI)},
                                            @{@"蓝牙":@(RSPrefsRoot_Bluetooth)},
                                        ]
                                    }];
    
    [_resourceDataMuAry addObject:@{@"2":@[
                                            @{@"通知":@(RSPrefsRoot_Notification)},
                                            ]
                                    }];
    
    //通用设置
    [_resourceDataMuAry addObject:@{@"3通用设置":@[
                                                @{@"通用设置":@(RSPrefsRoot_General)},
                                                @{@"关于本机":@(RSPrefsRoot_General_About)},
                                                @{@"软件升级":@(RSPrefsRoot_General_SoftwareUpdateLink)},
                                                
                                                @{@"Accessibility(辅助功能)":@(RSPrefsRoot_General_Accessibility)},
                                                
                                                @{@"通用－自动锁定":@(RSPrefsRoot_General_Autolock)},
                                                @{@"日期时间":@(RSPrefsRoot_General_DateAndTime)},
                                                @{@"键盘设置":@(RSPrefsRoot_General_Keyboard)},
                                                @{@"语言和地区":@(RSPrefsRoot_General_LanguageAndRegion)},
                                                
                                                @{@"VPN":@(RSPrefsRoot_General_VPN)},
                                                
                                                @{@"还原设置":@(RSPrefsRoot_General_Reset)},
                                              ]
                                    }];
  
    [_resourceDataMuAry addObject:@{@"4":@[
                                            @{@"壁纸设置":@(RSPrefsRoot_Wallpaper)},
                                            @{@"声音设置":@(RSPrefsRoot_Sounds)},
                                            ]
                                    }];
    
    //隐私设置
    [_resourceDataMuAry addObject:@{@"5隐私设置":@[
                                                @{@"隐私设置":@(RSPrefsRoot_Privacy)},
                                                @{@"定位服务":@(RSPrefsRoot_Location_Services)},
                                              ]
                                    }];
    
    [_resourceDataMuAry addObject:@{@"6":@[
                                            @{@"设置－iCloud 界面":@(RSPrefsRoot_Castle)},
                                            @{@"设置－iCloud－存储空间":@(RSPrefsRoot_Castle_StorageAndBackup)},
                                            @{@"APP Store":@(RSPrefsRoot_Store)},
                                            ]
                                    }];
    
    [_resourceDataMuAry addObject:@{@"7":@[
                                            @{@"备忘录":@(RSPrefsRoot_Notes)},
                                            @{@"电话":@(RSPrefsRoot_Phone)},
                                            @{@"FaceTime":@(RSPrefsRoot_FaceTime)},
                                            @{@"Safari":@(RSPrefsRoot_Safari)},
                                            ]
                                    }];
    
    [_resourceDataMuAry addObject:@{@"8":@[
                                            @{@"音乐":@(RSPrefsRoot_Music)},
                                            @{@"照片与相机":@(RSPrefsRoot_Photos)},
                                            ]
                                    }];
    
    [_resourceDataMuAry addObject:@{@"9":@[
                                            @{@"Twitter":@(RSPrefsRoot_Twitter)},
                                            @{@"Facebook":@(RSPrefsRoot_Facebook)},
                                            @{@"Flickr":@(RSPrefsRoot_Flickr)},
                                            @{@"Vimeo":@(RSPrefsRoot_Vimeo)},
                                            ]
                                    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return _resourceDataMuAry.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    NSArray * cellAry   =   [[_resourceDataMuAry[section] allValues] firstObject];
    return cellAry.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSArray * cellAry   =   [[_resourceDataMuAry[indexPath.section] allValues] firstObject];
    NSDictionary * cellDic  =   cellAry[indexPath.row];
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    cell.textLabel.text =   cellDic.allKeys.firstObject;
    return cell;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return [[_resourceDataMuAry[section] allKeys] firstObject];
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/


#pragma mark - Table view delegate

// In a xib-based application, navigation from a table can be handled in -tableView:didSelectRowAtIndexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSArray * cellAry   =   [[_resourceDataMuAry[indexPath.section] allValues] firstObject];
    NSDictionary * cellDic  =   cellAry[indexPath.row];
    
    DLog(@"%@-%d",cellDic.allKeys.firstObject,(int)[cellDic.allValues.firstObject integerValue]);
    
    [RSSystemUtit jumpToSettingPageByRSPrefsRoot:(RSPrefsRoot)[cellDic.allValues.firstObject integerValue]];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
